home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000141_icon-group-sender_Thu Sep 6 12:55:23 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f86JsQ212824
for icon-group-addresses; Thu, 6 Sep 2001 12:54:26 -0700 (MST)
Message-Id: <200109061954.f86JsQ212824@baskerville.CS.Arizona.EDU>
From: Steve Wampler <swampler@noao.edu>
X-Newsgroups: comp.lang.icon
Subject: Re: join
Date: Thu, 06 Sep 2001 09:58:35 -0700
X-Complaints-To: abuse@noao.edu
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1448
Andrew Hamm wrote:
>
> dodod wrote in message <3B8C3D59.AA150BB8@hotmail.com>...
> >hello
> >i would like to write a program to emulate
> >unix join command but i do not know how to start
> >can you give me a hint or an example ?
> >
....
> I suppose it could also be programmed without the use of coroutines, but
> where's the fun in that?
A *long* time ago I wrote a short program to "pair" the lines
of two files using co-expressions (the basic stuff took 4 statements).
Then I realized that the functionality the program was using from the co-expressions
behavior is *exactly* the behavior provided by read()...
[A question for people: How equivalent are the following approaches?
f := open(filename)
while line := read(f) do ...
close(f)
and
cf := create (!(f := open(filename)) | (close(f),&fail))
while line := @cf do ...
]
Anyway, switching to read() instead of coroutines cut the basic
algorithm down to 2 statements.
Here's the basic algorithm for this "pairing":
# Output pairs of lines from files f1 and f2, where each pair
# is joined on a single output line.
#
procedure pair(f1, f2)
while write( read(f1), read(f2)|"")
while write( read(f2) )
end
join's basic algorithm isn't much worse, but there's a lot of
ugliness to handle the fields [still cleaner than in C, I imagine!].
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu